package cn.springcloud.fix.stomp.controller;

import cn.springcloud.fix.stomp.config.AppProperties;
import cn.springcloud.fix.stomp.service.WsSubscribeService;
import cn.springcloud.fix.stomp.utils.CommonUtil;
import cn.springcloud.fix.stomp.utils.FileUtil;
import cn.springcloud.fix.stomp.utils.FtpUtil;
import cn.springcloud.fix.stomp.vo.BaseResponse;
import cn.springcloud.fix.stomp.vo.FileVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class SubscribeController {

    @Autowired
    private AppProperties appProperties;
    @Autowired
    private WsSubscribeService wsSubscribeService;

    /**
     * 广播消息消息订阅，用于推送系统通知，广播所有用户
     */
    @SubscribeMapping({"/topic/system"})
    public BaseResponse handleBroadcastMessage(@Headers StompHeaderAccessor headers) {
        log.info("Received a new message withUser --> {}, destination: {}", headers.getUser().getName(), headers.getDestination());
        return wsSubscribeService.subscribe(headers);
    }


    @SubscribeMapping({"/queue/message", "/queue/event-alarm", "/queue/device-alarm", "/queue/voice-call"})
    public BaseResponse handleUserMessage(@Headers StompHeaderAccessor headers) {
        log.info("Received a new message withUser --> {}, destination: {}", headers.getUser().getName(), headers.getDestination());
        return wsSubscribeService.subscribe(headers);
    }
}
